<template>
  <div class="my-page bg-c2">
    <div class="myheaderbox">
      <div class="headerlogo">
        <img src="../../assets/img/photo.png">
      </div>
      <div style="display:flex; justify-content: center">
        <h5 id="nick_name"
          class="fs22 c1">{{mydata.nickName}}</h5>
        <!-- <span class="fs16 c7" v-if="mydata.realFlag">【节点商】</span> -->
      </div>
      <h2 id="user_name">{{mydata.userName}}</h2>
      <!-- <div class="signin" @click="handleSign">签到</div> -->
    </div>
    <div class="mycontentbox">
      <div class="contentbox-item">
        <div class="mycontent_head">
          <p>JDC资产</p>
          <span @click="doWithdraw(6)"
            class="c3">JDC提现</span>
        </div>
        <div class="ul-wrap">
          <ul>
            <li>
              <h3>锁仓数量</h3>
              <p id="integral">{{gicData.integral ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>可提数量</h3>
              <p id="can_extract_amount">{{gicData.canExtractAmount ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>已提数量</h3>
              <p id="withdraw_amount">{{gicData.withdrawAmount ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>{{balanceDay|fetchDay}}日余额</h3>
              <p id="integral">{{DayDealData.yesterdayAmount ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>{{yesterday | fetchDay}}日买入量</h3>
              <p id="can_extract_amount">{{DayDealData.amountBuy ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>{{yesterday | fetchDay}}日卖出量</h3>
              <p id="withdraw_amount">{{DayDealData.amountSell ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>{{yesterday | fetchDay}}日新增持仓量</h3>
              <p id="integral">{{DayDealData.beforeTrans || 0 | twoFloat}}</p>
            </li>
            <li>
              <h3>应释放量</h3>
              <p id="can_extract_amount">{{DayDealData.releaseAmount || 0 |twoFloat}}</p>
            </li>
            <li>
              <div class="state">
                <h3>状态</h3>
              </div>
              <p id="withdraw_amount">{{$consts.MAPS.VERIFY[DayDealData.verify] || '未释放' }}</p>
            </li>
            <li>
              <router-link to="my/rule"
                tag="span"
                class="c3 fs14">释放规则</router-link>
            </li>
          </ul>
        </div>
      </div>

      <div class="contentbox-item">
        <div class="mycontent_head">
          <p>{{depositPlanData.planName || 'JDC存款计划' }}</p>
          <span class="c3"
            @click="showFlag = !showFlag">存款</span>
        </div>
        <div class="ul-wrap">
          <ul>
            <li>
              <div class="state">
                <h3>当前存款</h3>
              </div>
              <p id="integral">{{reapData.deposit_total ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>累计收益</h3>
              <p id="can_extract_amount">{{reapData.grand_total ||0 | twoFloat}}</p>
            </li>
            <li>
              <h3>今日收益</h3>
              <p id="withdraw_amount">{{ reapData.grand_day ||0 | twoFloat}}</p>
            </li>
            <li class="fs14 c3">
              <router-link to="my/depositExplain"
                class="fs14 c3"> 存款说明</router-link>
            </li>
            <li class="fs14 c3">
              <router-link to="my/depositRecord"
                class="fs14 c3"> 存款记录</router-link>
            </li>
          </ul>
          <div class="progress-text-wrap">
            <span class="text fs14">剩余：{{depositPlanData.totalNum - depositPlanData.remainderNum || 0}}</span>
            <span class="text fs14">总投放数：{{depositPlanData.totalNum || 0}}</span>

          </div>
          <progress :value="depositPlanData.totalNum - depositPlanData.remainderNum || 0"
            :max="depositPlanData.totalNum || 0">
          </progress>
        </div>

        <div class="deposit-shade"
          v-show="showFlag">
          <div class="top"
            @click="showFlag = false"></div>
          <div class="content">
            <div class="wrap">
              <div class="left">
                <p class="title">选择数量</p>
                <div class="label-wrap"
                  v-for="(item,index) in depositSumData"
                  :key="index">
                  <label>
                    <input type="radio"
                      name="amount"
                      v-model="depositValue"
                      :value="item">
                    <span class="text">{{item}}</span>
                  </label>
                </div>
              </div>
              <div class="right">
                <p class="title">选择周期</p>
                <div class="label-wrap"
                  v-for="(item,index) in planDayData"
                  :key="index">
                  <label>
                    <input type="radio"
                      name="plan"
                      v-model="planValue"
                      :value="item.cycle">
                    <span class="text">{{item.gradeDesc}}</span>
                  </label>
                </div>
              </div>
            </div>
            <div class="commit"
              @click="handleCommit">提交申请</div>
          </div>
        </div>
      </div>
      <!-- <div class="contentbox-item">
        <div class="mycontent_head">
          <p>推广收益</p>
          <router-link to="my/group">
            <P class="c3">查看团队</P>
          </router-link>
        </div>
        <div class="ul-wrap">
          <ul>
            <li>
              <h3>团队</h3>
            </li>
            <li>
              <h3>一级</h3>
            </li>
            <li>
              <h3>二级</h3>
            </li>
            <li>
              <h3>人数</h3>
            </li>
            <li>
              <span>{{release[0].pnum_one || 0}}</span>
            </li>
            <li>
              <span>{{release[0].pnum_too|| 0}}</span>
            </li>
            <li>
              <h3>团队贡献</h3>
            </li>
            <li>
              <span>{{release[2].total_one || 0 | twoFloat}}</span>
            </li>
            <li>
              <span>{{release[2].total_too || 0 | twoFloat}}</span>
            </li>
          </ul>
        </div>
      </div>
      <div class="contentbox-item">
        <div class="mycontent_head">
          <p>节点收益</p>
          <span @click="doWithdraw(3)"
            class="c3">USDT提现</span>
        </div>
        <div class="item-bottom-wrap">
          <ul>
            <li>
              <h2>节点人数</h2>
              <span>{{nodeData.pnum || 0 }}</span>
            </li>
            <li>
              <h2>节点商数</h2>
              <span>{{nodeData.totalreleasenum || 0 }}</span>
            </li>
            <li>
              <h2>USDT收益</h2>
              <span>{{nodeData.integral || 0 | twoFloat}}</span>
            </li>
            <li>
              <h2>USDT可提数</h2>
              <span>{{nodeData.dayreleasenum || 0 | twoFloat}}</span>
            </li>
          </ul>
        </div>
      </div>-->
    </div>
    <div class="quit-wrap">
      <button class="quitbtn"
        @click="logout()">安全退出</button>
    </div>
  </div>
</template>

<script>
import * as z from "@/utils/com.js";
import * as r from "@/utils/validate.js";
import { parseTime } from "@/utils/com.js";
import { Indicator } from "mint-ui";
import { MessageBox } from "mint-ui";

const B_TYPE = 6;

export default {
  created() {
    this.mydata = JSON.parse(this.$auth.get()["localdata"]);
    if (this.mydata.userType != 3) {
      this.logout();
    }
    this.getUserInfo();
    // this.getReleaseData(); //释放收益
    this.getGicData(); //GIC
    this.getDayDeal(); //当日交易量
    // this.getNodeData(); //节点收益
    // this.getDaySign(); //当日签到信息
    this.getDepositData(); //存款数量
    this.getPlanData(); //存款周期
    this.getReapData(); //存款收益
  },
  data() {
    return {
      mydata: {},
      gicData: [{}],
      DayDealData: {},
      nodeData: {},
      release: [{}, {}, {}, {}],
      selectSumDate: {},
      depositSumData: [],
      depositPlanData: {},
      planDayData: [],
      reapData: {},
      showFlag: false,
      depositValue: "500",
      planValue: "30"
    };
  },
  computed: {
    yesterday: function () {
      let curDate = new Date();
      let preDate = new Date(curDate.getTime() - 24 * 60 * 60 * 1000); //前一天
      let preDateRes = parseTime(preDate);
      return preDateRes.substring(0, 10);
    },
    balanceDay: function () {
      let curDate = new Date();
      let preDate = new Date(curDate.getTime() - 24 * 60 * 60 * 1000 * 2);
      let preDateRes = parseTime(preDate);
      return preDateRes.substring(0, 10);
    }
  },
  methods: {
    doWithdraw(kindId) {
      let reg = /^[0-9](\.\d+)?/;
      z.prompt("请输入您需要提现的数量", async val => {
        if (!reg.test(val.value)) {
          z.alert("请输入正确的数字");
          return;
        }
        let response = await this.$http.post(
          "/bus/withdraw/do",
          this.$qs.stringify({
            userId: JSON.parse(localStorage.getItem("localdata")).uuid,
            amount: val.value,
            withdrawType: kindId
          })
        );
        z.alert(response.data.msg);
      });
    },

    logout() {
      this.$auth.logout();
      window.location.href = "/auth/login/logout";
    },

    // async getReleaseData() {
    //   let response = await this.$http.post(
    //     "/sys/partner/parreport",
    //     this.$qs.stringify({
    //       userId: this.mydata.uuid
    //     })
    //   );
    //   if (200 == response.data.code) {
    //     this.release = response.data.data;
    //   } else {
    //     z.alert(response.data.msg);
    //   }
    // },

    async getGicData() {
      let gicRes = await this.$http.post(
        "/bus/account/getaccount",
        this.$qs.stringify({
          accountType: B_TYPE
        })
      );
      if (200 == gicRes.data.code && gicRes.data.data) {
        this.gicData = gicRes.data.data;
      }
    },

    async getDayDeal() {
      let DayDealRes = await this.$http.post(
        "/bus/release/releaseday",
        this.$qs.stringify({
          releaseType: B_TYPE
        })
      );
      if (DayDealRes.data.code == 200 && DayDealRes.data.data) {
        this.DayDealData = DayDealRes.data.data;
      }
    },

    // async getNodeData() {
    //   let nodeRes = await this.$http.post(
    //     "/sys/partner/nodereport",
    //     this.$qs.stringify({
    //       currencyId: 3
    //     })
    //   );
    //   if (nodeRes.data.code == 200) {
    //     this.nodeData = nodeRes.data.data;
    //   }
    // },

    async getUserInfo() {
      let userRes = await this.$http.post(
        "/sys/user/curinfo",
        this.$qs.stringify({})
      );
      this.userInfo = userRes.data.data;
    },

    // async getDaySign() {
    //   let daySignRes = await this.$http.post(
    //     "/bus/signin/dayinfo",
    //     this.$qs.stringify({
    //       userId: this.mydata.uuid
    //     })
    //   );
    // },
    // handleSign() {
    //   let daySignRes = this.$http.post(
    //     "/bus/signin/do",
    //     this.$qs.stringify({
    //       userId: this.mydata.uuid
    //     })
    //   );
    // }
    async getDepositData() {
      let depositRes = await this.$http.post(
        "/bus/plan/get",
        this.$qs.stringify({
          planId: "JDC20190115"
        })
      );
      this.depositPlanData = depositRes.data.data
      this.depositSumData = depositRes.data.data.planDesc.split(",");
    },
    async getPlanData() {
      let planRes = await this.$http.post(
        "/bus/plan/grades",
        this.$qs.stringify({
          planId: "JDC20190115"
        })
      );
      if (planRes.data.code == 200) {
        this.planDayData = planRes.data.data;
      }
    },
    async getReapData() {
      let reapRes = await this.$http.post(
        "/bus/invest/count",
        this.$qs.stringify({})
      );
      if (reapRes.data.code == 200) {
        this.reapData = reapRes.data.data;
      }
    },
    handleCommit() {
      MessageBox({
        title: "提示",
        message: `存款数额：${this.depositValue}</br>存款周期：${
          this.planValue
          }天`,
        showCancelButton: true
      }).then(async res => {
        if (res == "confirm") {
          this.showFlag = false;
          Indicator.open();
          let commitRes = await this.$http.post(
            "/bus/invest/do",
            this.$qs.stringify({
              planId: "JDC20190115",
              investNum: this.depositValue,
              grade: this.planValue
            })
          );
          console.log(commitRes.data);

          if (commitRes.data.code == 200) {
            this.reapData.deposit_total += Number(this.depositValue);
            z.alert("存款成功");
          } else if (commitRes.data.code == 101027) {
            z.alert('存款失败，您的余额不足');
          } else {
            z.alert(commitRes.data.msg)
          }
          Indicator.close();
        }
      });
    }
  },

  mounted() {
    setInterval(val => {
      this.getUserInfo();
      this.getGicData();
      if (!this.userInfo) {
        this.logout();
      }
    }, 20000);
  }
};
</script>
<style lang="scss" scoped src="./styles/index.scss">
</style>

